package com.mstore.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.mstore.pojo.Account;
import com.mstore.pojo.Notice;
import com.mstore.service.NoticeService;

public class NoticeAction extends BaseAction implements SessionAware {

	private static final long serialVersionUID = 7078963229105084213L;

	private Map<String, Object> session;

	private String result;

	private List<Notice> notices;

	private NoticeService noticeService;

	private Notice notice;

	private Integer type;

	/**
	 * 搜索企业的通知 目前只有消费退换和充值退换 表现形式为： 1、有N条消费退换申请 2、有N条充值退换申请
	 */
	public String searchEaNotices() {
		Object object = session.get("account");
		if (object == null) {
			result = "系统异常，请重新登陆！";
			return "error";
		}
		Account account = (Account) object;

		Long eaId = account.getId();

		notices = noticeService.getCountNoticesByType(eaId);

		result = listTojson(notices);

		return SUCCESS;
	}

	/**
	 * 修改通知状态为已阅读
	 */
	public String modifyReadStatus() {
		Object object = session.get("account");
		if (object == null) {
			result = "系统异常，请重新登陆！";
			return "error";
		}
		Account account = (Account) object;
		
		Map<String, Object> map = new HashMap<String, Object>();
		if (type != null) {
			noticeService.modifyReadStatus(account.getId(), type);
			map.put("temp", "ok");
		}else {
			map.put("temp", "no");
		}
		
		result = mapTojson(map);
		
		return SUCCESS;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public List<Notice> getNotices() {
		return notices;
	}

	public void setNotices(List<Notice> notices) {
		this.notices = notices;
	}

	public NoticeService getNoticeService() {
		return noticeService;
	}

	public void setNoticeService(NoticeService noticeService) {
		this.noticeService = noticeService;
	}

	public Notice getNotice() {
		return notice;
	}

	public void setNotice(Notice notice) {
		this.notice = notice;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

}
